<script type="text/javascript">
	$(document).ready(function(){
	});
</script>

<?php
	session_start();

	require_once("includes/connect.php");
	require_once("includes/function.php");

  	$panngan2 = $_REQUEST["panngan2"];
	$panngan3 = $_REQUEST["panngan3"];

	$budget_year = $_REQUEST["budget_year"];

	$month_year = $_REQUEST["month_year"];
	
	$ex1_id = $_REQUEST["ex1_id"];
	$ex2_id = $_REQUEST["ex2_id"];

	$amount = $_REQUEST["amount"];

	$utility_id = $_REQUEST["utility_id"];

	$task = $_REQUEST["task"];
	//$task = "new";

/*
	if(isset($utility_id)) {
		$task = "edit";
	} else {
		$task = "new";
	}
*/
	$db = new myDBS;

	switch($task) {
		case "new":
			$running = $db->get_running($budget_year);

			$sql = "INSERT INTO tbl_utility (lvl1_id, panngan2_id, panngan3_id, ex1_id, ex2_id, month_year, 
						utility, pet_id, budget_year)
						VALUES ('" .$_SESSION["lvl1_id"]. "', '$panngan2', '$panngan3', '$ex1_id', '$ex2_id', '$month_year', '$amount', '$running', '$budget_year');
						";
			//echo $sql;
			$db->runSQL($sql);
			break;
		case "edit":
			$sql = "UPDATE tbl_utility SET panngan2_id = '$panngan2', panngan3_id = '$panngan3', 
						ex1_id = '$ex1_id', ex2_id = '$ex2_id', month_year = '$month_year', 
						utility = '$amount', budget_year = '$budget_year'
						WHERE utility_id = '$utility_id'
						";
			$db->runSQL($sql);
			break;
		case "del":
			$sql = "DELETE FROM tbl_utility WHERE utility_id = '$utility_id'";
			$db->runSQL($sql);
			break;
	}
	
?>
